﻿using System.Web.Mvc;
using MyWebApp.Data;
using Newtonsoft.Json;

namespace MyWebApp.Controllers
{
    public class HomeController : Controller
    {
        private readonly IBikesSearchService _bikesSearchService;

        public HomeController(IBikesSearchService bikesSearchService)
        {
            _bikesSearchService = bikesSearchService;

            var latestBikes = _bikesSearchService.GetLatestBikes();

            var serializedLatestBikes = JsonConvert.SerializeObject(latestBikes);

            ViewBag.LatestBikes = serializedLatestBikes;
        }

        public ActionResult Index()
        {
            ViewBag.Title = "BikeFindr";

            return View();
        }
    }
}
